﻿@model IEnumerable<KPIS.GERP.Models.SYS.Message> 

@{ 
    ViewBag.Title = "กล่องข้อความของคุณ";
    if(ViewBag.noLayout == true)
    {
        Layout = "~/Views/Shared/_EmptyLayout.cshtml";
    }
    string stringUrl = "";
}
 
    @Html.AntiForgeryToken()
<div class="row-fluid">
    @*@if(ruleApproveGroup != null)
    {
        <div class="alert alert-block alert-info">
            <button type="button" class="close" data-dismiss="alert">
                <i class="icon-remove"></i>
            </button>

            <i class="icon-ok green"></i>
 
            แสดงเฉพาะ "@ruleApproveGroup.rule_approve_group_name"
            <a href="@Url.Action("TaskMessageInbox")">แสดงทั้งหมด</a>
        </div>
    }*@

    @Html.ValidationSummary(true, "", new { @class = "alert alert-error" })
    <div class="row-fluid">
        <div class="table-header span12">
            <div class="span10">
                @ViewBag.Title
            </div>
            @Html.Partial("_ExportButton")
        </div>
    </div>

    <table id="table" class="table table-bordered table-hover" aria-describedby="table_info">
        <thead>
            <tr>
                <th></th>  
                <th>#</th>  
                <th>รหัสอ้างอิง</th>
                <th>ประเภทคำขอ</th>
                <th>หัวข้อคำขอ</th> 
                <th>ชื่อผู้ส่ง</th> 
                <th>สังกัด</th> 
                <th>วันที่ส่ง</th> 
            </tr>
        </thead>
        <tbody>
            @foreach(var message in Model.Where(o=>o.RecordStatus != "D").OrderByDescending(o=>o.MessageId))
            { 
                stringUrl = Url.Action("TaskMessageDetails", "ApprovalTask",
                                        new RouteValueDictionary
                                            {
                                                {
                                                    "taskMessageSeq", message.MessageId
                                                },
                                                {
                                                    "noLayout", ViewBag.noLayout
                                                } /*,
                                                {"ruleApproveGroupSeq",  ruleApproveGroupSeq}*/
                                            });
                <tr class="@(message.MessageStatus != MessageWarningStatus.Read ? "NewMessageStyle" : "")" title="@(string.IsNullOrWhiteSpace(message.MessageStatus.ToString()) ? "" : "[" + message.MessageStatus +"]") @message.Title">
                    
                    <td>
                        <i class="@(message.MessageStatus != MessageWarningStatus.Read ? "icon-envelope-alt" : "icon-envelope")" ></i>
                    </td>
                    <td>@message.MessageId</td>
                    
                    <td>
                        <a href="@stringUrl" >@message.Code</a> 
                    </td>
                    <td>
                        <a href="@stringUrl" >
                            @(message.ApprovalTaskDtl != null && message.ApprovalTaskDtl.ApprovalTask != null && message.ApprovalTaskDtl.ApprovalTask.OriginalApproveProcess != null && message.ApprovalTaskDtl.ApprovalTask.OriginalApproveProcess.ApproveProcessGroup != null ?  message.ApprovalTaskDtl.ApprovalTask.OriginalApproveProcess.ApproveProcessGroup.Name : "")
                            </a> 
                    </td>
                    <td>
                        <a href="@stringUrl" >
                                @ConvertUtility.LimitCharactor(message.Title, 200)
                            </a> 
                    </td>
                    <td>
                            @Html.DisplayFor(m => message.FromEmployee.FullName)
                       
                    </td>
                    <td>
                        
                        
                            @Html.DisplayFor(m => message.FromEmployee.JobSite.Name)
                    </td>
                    <td>@(message.Date.HasValue ? message.Date.Value.ToString("dd MMM yy") : null)</td>
                </tr>
            }
        </tbody>
    </table>
</div> 

<style type="text/css">
    .content {
        padding: 5px 10px;
        background-color:#fafafa; 
    }
    .heading {
        margin: 1px;
        color: #0366a5;
        padding: 3px 10px;
        cursor: pointer;
        position: relative;
        background-color:#d4e7ea;
    }
    .NewMessageStyle {
        font-weight: bolder;
         background-color:#f8f8f8; 
    }
</style>

@section scripts {
<script type="text/javascript">
    $(function () {
        $("#table")
            .dataTable({
                "aaSorting": [[1, "desc"]]
            });
		//$('#table').dataTable({
		//    "aoColumns": [
        //        { "bSortable": true }, 
        //        null,
        //        null,
        //        null,
        //        null
		//	]
		//});

		@*$('table th input:checkbox').on('click', function () {
			var that = this;
			$(this).closest('table').find('tr > td:first-child input:checkbox')
			.each(function () {
				this.checked = that.checked;
				$(this).closest('tr').toggleClass('selected');
			});

		});

		$('[data-rel=tooltip]').tooltip();

		$("#form").submit(function (e) {
			e.preventDefault();
			var currentForm = this;
			bootbox.confirm("คุณแน่ใจหรือไม่", function (c) {
				if (c) {
					$.ajax({
						url: "@Url.Action("DeleteAll")",
			    		type: "post",
			    		dataType: "json",
			    		data: $(currentForm).serialize(),
			    		context: document.body,
			    		success: function (s) {
			    			if (s.success) {
			    				location.reload();
			    			}
			    		},
			    		error: function (xhr, status, error) {
			    			alert("Status: " + status + ", Error: " + error + ", XHR: " + xhr.readyState);
			    		},
			    		statusCode: {
			    			404: function () {
			    				alert("Page not found");
			    			}
			    		}
			    	});
				}
			});
			return false;
		});*@
	})

</script>
}